function getArticleCat() {
    $.ajax({
        url: '/my/article/cates',
        success: function(res) {
            var str = template('text-content', res)
            $('tbody').html(str)
        }
    })
}


var index
$('add-cat').on('click', function() {
        index = layer.open({
            title: '添加分类',
            content: template('layer-add', {}),
            btn: null,
            area: ['500px', '250px']

        })

    })
    // 新增分类

$('body').on("submit", ".add-form", function() {
    $.ajax({
        url: "/my/article/addcates ",
        method: 'POST',
        data: $(this).serialize(),
        success: function(res) {
            console.log(res);
            // 提示用户
            layer.msg(res.message)
                // 关闭弹窗
            layer.close(index)
            getArticleCat()
                //渲染页面
        }
    })
})

$('tbody').on('click', 'edit', function() {
    var $this = $(this)
    index = layer.open({
        title: '编辑分类',
        content: template('edit-cate', {}),
        btn: null,
        area: ['500px', '250px'],
        success: function() {

            $.ajax({
                url: "/my/article/cates/" + $this.attr('data-id'),
                success: function(res) {
                    console.log(res);

                    layui.form.val('edit', res.data)
                }

            })
        }
    })
})



$('body').on('submit', 'edit-form', function(e) {
    e.preventDefault()
    $.ajax({
        url: "/my/article/updatecate ",
        method: 'POST',
        data: $(this).serialize(),
        success: function(res) {
            console.log(res);
            // 提示用户
            layer.msg(res.message)
                // 关闭弹窗
            layer.close(index)
            getArticleCat()
                //渲染页面
        }
    })
})

$('tbody').on('click', 'delete', function() {

    layer.confirm('是否', { icon: 3, title: '提示' }, function(index) {
        //do something
        $.ajax({
            url: '/my/article/deletecate/' + id,
            success: function(res) {
                layer.msg(res.message)

                getArticleCat()
            }

        })

        layer.close(index);
    });


})